// VirtualOps.Vix.h
#include "vix.h"

class VixHandleGuard
{
public:
   
    VixHandleGuard(VixHandle handle) : _handle(handle) {}
    
    /** To release the handle whenever we go out of scope */
    ~VixHandleGuard()
    {
        if (_handle != VIX_INVALID_HANDLE) { Vix_ReleaseHandle(_handle); }
    }

    /** To use VixHandleGuard just like VixHandle */
    operator VixHandle() { return _handle; }
    
    /** To pass VixHandleGuard where VixHandle is passed by pointer, 
        like  VixJob_Wait(...) */
    VixHandle * operator & () { return &_handle; }

private:
    VixHandle _handle;
    /** To restrict copying the Guard */
    VixHandleGuard (const VixHandleGuard&);

};